|
|
|
|
|
|
|
cell in the grid, you can edit that cell. As soon as you leave the row, that cell is updated by Visual Basic 5. Right now, you cannot add or delete records from the grid. You'll add those features in the next example. |
|
|
|
|
|
|
|
|
Adding and Deleting Records with the Data-Bound Grid |
|
|
|
|
|
|
|
|
It's very easy to include add and delete capabilities with the data grid. Bring up the same project you just completed. Select the data grid control and press F4 to bring up the Properties window. Locate the AllowAddNew property and the AllowDelete property and set them to True. You now have add and delete power within the grid. |
|
|
|
|
|
|
|
|
Before you run this project, make two other changes. Set the Visible property of the data control to False. Because you can navigate through the grid using scroll bars and the mouse, you don't need the data control arrow buttons. Second, set the Align property of the grid control to 1 vbAlignTop. This forces the grid to hug the top and sides of the form whenever it is resized. |
|
|
|
|
|
|
|
|
Now save and run the project. Notice that you can resize the columns. Figure 12.11 shows the resized form with several columns adjusted. |
|
|
|
|
|
|
|
|
Figure 12.11.
Resizing the form and columns of a data grid control. |
|
|
|
|
|
|
|
|
To add a record to the data grid, all you need to do is place the cursor at the first field in the empty row at the bottom of the grid and start typing. Use Figure 12.12 as a guide. Visual Basic 5 creates a new line for you and allows you to enter data. Take note how the record pointer turns into a pencil as you type. When you leave the line, Visual Basic 5 saves the record to the dataset. |
|
|
|
|
|